﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _10_C_中的隐式转换和显式转换
{
    internal class MyInt
    {
        //implicit 隐式转换  explicit 显示转换
        private int MyIntValue;

        private string MyStringValue;

        public MyInt(int tvalue) { MyIntValue = tvalue; }

        public static implicit operator double(MyInt myInt)//将括号里面的类型转换成外面的类型
        {        //隐式转换
            return myInt.MyIntValue;
        }

        public static implicit operator string(MyInt myInt)//将括号里面的类型转换成外面的类型
        {        //隐式转换
            return myInt.MyStringValue;
        }

        public static explicit operator MyInt(double num)//将括号里面的类型转换成外面的类型
        {
            return new MyInt(Convert.ToInt32(num));
        }
    }
}
